﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace msBsc.WebUi.wMall.Public
{
    public partial class wfUserRegister : msBsc.Cls.BPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        private void Register()
        {
            string account = this.GetParamHtValue("account");
            string password = this.GetParamHtValue("password");
            string okPassword = this.GetParamHtValue("okPassword");
            string invatationCode = this.GetParamHtValue("invatationCode");
            string code = this.GetParamHtValue("code");
            //
            if (code != (string)GetSession(this.sCurrPageRadom + msBsc.Cls.ValidateCode.VALIDATECODEKEY, "2"))
            {
                this.ExecJScript("layer.alert('验证码错误或已过期，请重新录入！', 3);jQuery.getValidateImg('imgValidata');");
                return;
            }
            if (string.IsNullOrEmpty(account) || string.IsNullOrEmpty(password))
            {
                this.ExecJScript("layer.alert('注册失败：账户名和密码不能为空', 3);");
                return;
            }
            if (password != okPassword)
            {
                this.ExecJScript("layer.alert('注册失败：密码和确认密码不一致', 3);");
                return;
            }
            using (msBsc.AppLogic.DataAlc.CBizCustomerRegister register = new msBsc.AppLogic.DataAlc.CBizCustomerRegister())
            {
                string[] ret = register.AddCustomerInfo(account, password, invatationCode);
                if (ret[0] == "OK")
                {
                    string strurl = msBsc.AppLogic.Cfg.DesCry.encMe(account + "," + password + "," + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "," + invatationCode + "," + ret[1], "rmdes");
                    string url = msBsc.AppLogic.Cfg.SystemFileDir.FileDir.httpUrl + "wp_AccountVerify.htm?KEY=" + strurl;

                    string content = @"<div style='width:600px;font-size:14px; font-family:微软雅黑;padding-left:5px;text-decoration:none;'><div><span style='color:#1a9bf2'>{0}</span>,您好:</div><div style='padding-left:30px;'><div>感谢您使用地接客旅游网!</div><div>请点击如下连接，以完成您帐号的激活：</div><a style='text-decoration:none; color:#1a9bf2;' href='{1}'>{2}</a><div>(如果不能点击该连接地址，请复制并粘贴到浏览器的地址输入框)</div><div style='margin-left:400px;'>地接客旅游网</div><div style='margin-left:400px;'>{3}</div></div></div>";
                    msBsc.SvRef.SendEMail sendEmail = new msBsc.SvRef.SendEMail();
                    sendEmail.SendEmailTo(account, account, "地接客旅游帐户验证", string.Format(content, account, url, url, DateTime.Now.ToShortDateString()));
                    this.ExecJScript(@"layer.alert('注册成功，请去您的邮箱激活用户', 1);window.location.href = "" / """);
                }
                else
                {
                    this.ExecJScript("layer.alert('"+ret[1]+"', 3);jQuery.getValidateImg('imgValidata');");
                }
            }

        }

        public override void DoAction()
        {
            if (this.strAction == "init")
            {
                string invatationCode = this.GetParamHtValue("invatationCode");
                using (msBsc.AppLogic.DataAlc.CBizCustomerRegister register = new msBsc.AppLogic.DataAlc.CBizCustomerRegister())
                {
                    register.CustomerClick(invatationCode);
                }
                base.DoAction();
            }
            else if (this.strAction == "register")
            {
                Register();
            }
        }
    }
}